package com.example.android.ui.message;

import com.example.android.bean.BaseBean;
import com.example.android.bean.Message;
import com.example.android.ui.mine.MineContract;

import java.util.List;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class MessagePresenter implements MineContract.IMinePresenter {
    private MessageContract.IMessageView messageView;
    MessageContract.IMessageModel messageModel;
    public MessagePresenter(MessageContract.IMessageView messageView){
        this.messageView = messageView;
        messageModel = new MessageModel();
    }

    @Override
    public void getData() {
        messageModel.getMessage()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<BaseBean<List<Message>>>() {
                    @Override
                    public void accept(BaseBean<List<Message>> listBaseBean) throws Throwable {
                        messageView.getMessageSuccess(listBaseBean);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                        messageView.getMessageError(throwable);
                    }
                });
    }
}
